// pages/gallery/index/index.js
const UUID = require('../static/uuid')
Page({
  data: {
    isError: false,
    banner: [],
    info: ''
  },
  onLoad: function (options) {
    let uuid = tt.getStorageSync('gallery__uuid')
    if (!uuid) {
      tt.setStorageSync('gallery__uuid', UUID())
    }
    tt.request({ // 获取相册打印商品详情
      url: 'https://douyinmini.163ar.cn/admin/product/get?id=5da3d5da3f50de119e1b1235', // 目标服务器url
      success: (res) => {
        console.log('获取成功')
        console.log(res.data.data)
        this.setData({
          banner: res.data.data.pic_list,
          info: this.renderContent(res.data.data.content)
        })
        tt.setStorageSync('gallery__info', res.data.data);
      },
      fail (res) {
        console.log(res)
        this.setData({
          isError: true
        })
      }
    });
  },
  renderContent (src) {
    src = src.replace(/\<img/gi, '<img style="width:100%;max-width:100%;height:auto"')
    src = src.replace(/\<p/gi, '<p style="font-size:0;margin: 0"')
    src = src.replace(/http\:\/\/192.168.11.99:8360/gi, this.baseUrl)
    src = src.replace(/http\:\/\/192.168.11.99:3005/gi, this.baseUrl)
    return src
  },
  navto (e) {
    let url = e.currentTarget.dataset.url
    tt.reLaunch({
      url: url
    });
  }
})